package cn.iocoder.yudao.module.vos.service.activityfailednumbers;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.vos.controller.admin.activityfailednumbers.vo.*;
import cn.iocoder.yudao.module.vos.dal.dataobject.activityfailednumbers.ActivityFailedNumbersDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.vos.dal.mysql.activityfailednumbers.ActivityFailedNumbersMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.vos.enums.ErrorCodeConstants.*;

/**
 * 活动任务失败的具体名单号码信息 Service 实现类
 *
 * @author shijun
 */
@Service
@Validated
public class ActivityFailedNumbersServiceImpl implements ActivityFailedNumbersService {

    @Resource
    private ActivityFailedNumbersMapper activityFailedNumbersMapper;

    @Override
    public Long createActivityFailedNumbers(ActivityFailedNumbersSaveReqVO createReqVO) {
        // 插入
        ActivityFailedNumbersDO activityFailedNumbers = BeanUtils.toBean(createReqVO, ActivityFailedNumbersDO.class);
        activityFailedNumbersMapper.insert(activityFailedNumbers);

        // 返回
        return activityFailedNumbers.getId();
    }

    @Override
    public void updateActivityFailedNumbers(ActivityFailedNumbersSaveReqVO updateReqVO) {
        // 校验存在
        validateActivityFailedNumbersExists(updateReqVO.getId());
        // 更新
        ActivityFailedNumbersDO updateObj = BeanUtils.toBean(updateReqVO, ActivityFailedNumbersDO.class);
        activityFailedNumbersMapper.updateById(updateObj);
    }

    @Override
    public void deleteActivityFailedNumbers(Long id) {
        // 校验存在
        validateActivityFailedNumbersExists(id);
        // 删除
        activityFailedNumbersMapper.deleteById(id);
    }

    @Override
        public void deleteActivityFailedNumbersListByIds(List<Long> ids) {
        // 删除
        activityFailedNumbersMapper.deleteByIds(ids);
        }


    private void validateActivityFailedNumbersExists(Long id) {
        if (activityFailedNumbersMapper.selectById(id) == null) {
            throw exception(ACTIVITY_FAILED_NUMBERS_NOT_EXISTS);
        }
    }

    @Override
    public ActivityFailedNumbersDO getActivityFailedNumbers(Long id) {
        return activityFailedNumbersMapper.selectById(id);
    }

    @Override
    public PageResult<ActivityFailedNumbersDO> getActivityFailedNumbersPage(ActivityFailedNumbersPageReqVO pageReqVO) {
        return activityFailedNumbersMapper.selectPage(pageReqVO);
    }

}